import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/enums/index.dart';
import 'package:geomancy/mock/relations_data.dart';
import 'package:geomancy/providers/user_provider.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/tools/utils.dart';
import 'package:geomancy/widgets/common_btn.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/common_text.dart';
import 'package:geomancy/widgets/common_title.dart';
import 'package:geomancy/widgets/direction_grid/index.dart';
import 'package:geomancy/widgets/star_grid/index.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

class RelationsResultPage extends StatefulWidget {
  final CompassSource source;
  final double direction;///罗盘角度
  final String birthday;
  const RelationsResultPage({super.key, required this.source, required this.direction, required this.birthday});

  @override
  State<RelationsResultPage> createState() => _RelationsResultPageState();
}

class _RelationsResultPageState extends State<RelationsResultPage> {
  late int zodiacIndex;
  late String zodiacTxt;
  late String birthdayStr;
  late String directionStr;

  @override
  void initState() {
    super.initState();
    final index = Utils.getZodiacIndex(widget.birthday);
    final zodiac = Utils.getZodiacPinYinBybIndex(index);
    zodiacIndex = RelationsData.gridZodiacData[zodiac]['index'];
    zodiacTxt = Utils.getZodiacTxtBybIndex(index);
    birthdayStr = Utils.getFormatDate(dateTime: DateTime.parse(widget.birthday), format: 'YYYY年MM月DD日');
    directionStr = RelationsData.gridZodiacData[zodiac]['text'];
  }

  backHandle() {
    context.go('/');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonHeader.appBar(context: context),
      backgroundColor: ColorStyle.pageDefaultColor,
      body: ListView(
        physics: const ClampingScrollPhysics(),
        padding: EdgeInsets.fromLTRB(Constant.PAGEPADDING.w, 20.w, Constant.PAGEPADDING.w, 80.w),
        children: [
          const CommonTitleWidget(txt: '本命桃花位'),
          Container(
            margin: EdgeInsets.symmetric(vertical: 20.w),
            padding: EdgeInsets.all(40.w),
            // alignment: Alignment.center,
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText(txt: '个人命理信息：$birthdayStr，属$zodiacTxt', height: 1.5),
                CommonText(txt: '桃花位：$directionStr', height: 1.5),
              ],
            ),
          ),
          ///本命桃花九宫格
          DirectionGridWidget(
            activeList: [zodiacIndex],
            isOpacity: widget.source == CompassSource.stationRelations,
            source: widget.source,
            direction: widget.direction,
          ),
          Container(
            margin: EdgeInsets.only(top: 20.w, bottom: 80.w),
            padding: EdgeInsets.symmetric(vertical: 30.w, horizontal: 40.w),
            decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: const CommonText(height: 1.5, txt: '若本命人缘位与当年九宫飞星人缘位方位相重合，则本年度本命人缘位能量达到最佳，合理催动人缘位将更有助于婚姻美满及人际关系，且单身的朋友也能够找到最佳的伴侣。'),
          ),
          CommonTitleWidget(txt: '${Utils.getCurrentYear()}年 九宫飞星人缘位'),
          Container(
            margin: EdgeInsets.only(top: 20.w),
            child: const StarGridWidget(activeList: [0]),
          ),
        ],
      ),
    );
  }
}
